package com.example.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.model.CommonResult;
import com.example.entity.domain.Hierarchy;
import com.example.entity.dto.BaseDTO;
import com.example.service.HierarchicService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: zhuxiaokang
 * @CreateTime: 2025-05-07
 * @Description: 分级
 * @Version: 1.0
 */

@Tag(name = "分级管理")
@RestController
@RequestMapping("/hierarchy")
public class HierarchicController {


    @Resource
    private HierarchicService hierarchicService;


    @RequestMapping("/list")
    public CommonResult<Page<Hierarchy>> list(@RequestBody BaseDTO baseDTO) {
        return CommonResult.success(hierarchicService.list(baseDTO));
    }



    @RequestMapping("/current")
    public CommonResult<Integer> current() {
        return CommonResult.success(hierarchicService.current());
    }


    @RequestMapping("/add")
    public CommonResult<Boolean> add(@RequestBody Hierarchy hierarchy) {
        return CommonResult.success(hierarchicService.add(hierarchy));
    }


    @RequestMapping("/delete")
    public CommonResult<Boolean> delete(@RequestParam("id") Integer id) {
        return CommonResult.success(hierarchicService.delete(id));
    }


    @RequestMapping("/update")
    public CommonResult<Boolean> update(@RequestBody Hierarchy hierarchy) {
        return CommonResult.success(hierarchicService.update(hierarchy));
    }
}
